package com.myblog.controller;

import com.myblog.domain.GlobalResponse;
import com.myblog.domain.entity.enums.GlobalResponseEnum;
import com.myblog.expection.GlobalException;
import com.myblog.services.UploadService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
public class UploadController {
    @Resource
    UploadService uploadService;
    @PostMapping("/upload")
    public GlobalResponse upload(@RequestParam("img") MultipartFile img){
       try{
           return uploadService.upload(img);
       }
       catch (Exception e){
           throw new GlobalException(GlobalResponseEnum.ERROR.getCode(),"上传失败");
       }
    }
}
